'use strict';

const Controller = require('egg').Controller;

class HomeController extends Controller {
  async index() {
    const { ctx } = this;
    ctx.body = 'hi, egg';
  }

  async login() {
    let data = await this.ctx.service.home.login()
    this.ctx.body = data;
  }
  async register() {
    let data = await this.ctx.service.home.register()
    this.ctx.body = data;
  }

  async identity() {
    let { ctx, app } = this;
    if (ctx.state.user.userid == 0) {
      ctx.body = [
        {
          path: '/home',
          text: '首页'
        },
        {
          path: '/class',
          text: '教室'
        },
        {
          path: '/grade',
          text: '成绩'
        },
        {
          path: '/student',
          text: '学生'
        }
      ]
    } else {
      ctx.body = [
        {
          path: '/home',
          text: '首页'
        },
        {
          path: '/student',
          text: '学生'
        }
      ]
    }
  }
}

module.exports = HomeController;
